<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
	exit ('Access Denied');
}

/**
 * 每个 Logic 对应一个业务逻辑处理单元,必须继承自 BaseLogic
 * 每个 Logic 对应一个或多个 View/DAO
 */
class LogsLogic extends TinBaseLogic {

	private $logsDao;

	//需要有一个构造函数
	public function LogsLogic() {
		parent::__construct();
		$this->logger->className = "LogsLogic";
		$this->logsDao = Tin::getDAO("AssignTable","LOGS");
		$this->paylogDao = Tin::getDAO("AssignTable","PAYLOG");
	}
	//必须要一个释放函数
	public function __destruct(){
		parent::__destruct();
		$this->logsDao = null;
	}
	
	public function addLogs($data){
		try{
			$this->beginTrans();
			$map = Tin::createDataMap();  	
	    	$map->addEntry('TYPE_CODE', $data['type'], DB::VARCHAR);
	    	$map->addEntry('LOGTXT', $data['logs'], DB::VARCHAR);
	    	$map->addEntry('FROM_IP', ''.$_SERVER['REMOTE_ADDR'], DB::VARCHAR);
	    	$map->addEntry('CREATE_TIME', "'".date('Y-m-d H:i:s')."'", DB::DATE);
			$newid=$this->logsDao->insert($map, false, true);			
			$this->endTrans();
			return $newid;
		}catch(Exception $e){
            $this->giveUpTrans();
			$this->logger->error("addLogs:".$e->getMessage());			
			return null;
		}
	}	
	public function addPayLog($data){
		try{
			//$this->beginTrans();
			$map = Tin::createDataMap();  	
	    	$map->addEntry('LFTID', $data['lftid'], DB::VARCHAR);
	    	$map->addEntry('USERNAME', $data['username'], DB::VARCHAR);
	    	$map->addEntry('TOUSER', $data['otherName'], DB::VARCHAR);
	    	$map->addEntry('MONEY', $data['facevalue'], DB::VARCHAR);
	    	$map->addEntry('RAMRK', $data['remark'],DB::VARCHAR);
	    	$map->addEntry('CREATE_DATE', 'now()', DB::DATETIME);
			$logid = $this->paylogDao->insert($map, false, true);			
			//$this->endTrans();
			return $logid;
		}catch(Exception $e){
           // $this->giveUpTrans();
			$this->logger->error("addPayLog:".$e->getMessage());			
			return null;
		}
	}	

}//End Class
?>
